Make the "Controllers" field read-only.

Akinori MUSHA 10 年之前
父节点
当前提交
38de860670
共有 3 个文件被更改,包括 27 次插入15 次删除
  1. 4 0
      app/assets/stylesheets/application.css.scss.erb
  2. 17 5
      app/helpers/agent_helper.rb
  3. 6 10
      app/views/agents/_form.html.erb

+ 4 - 0
app/assets/stylesheets/application.css.scss.erb

@@ -60,6 +60,10 @@ img.odin {
60 60
   display: none;
61 61
 }
62 62
 
63
+.controller-region[data-has-controllers=false] {
64
+  display: none;
65
+}
66
+
63 67
 img.spinner {
64 68
   display: none;
65 69
   vertical-align: bottom;

+ 17 - 5
app/helpers/agent_helper.rb

@@ -19,10 +19,22 @@ module AgentHelper
19 19
   def agent_schedule(agent, delimiter = ', ')
20 20
     return 'n/a' unless agent.can_be_scheduled?
21 21
 
22
-    controllers = agent.controllers
23
-    [
24
-      *(CGI.escape_html(agent.schedule.humanize.titleize) unless agent.schedule == 'never' && agent.controllers.length > 0),
25
-      *controllers.map { |agent| link_to(agent.name, agent_path(agent)) },
26
-    ].join(delimiter).html_safe
22
+    case agent.schedule
23
+    when nil, 'never'
24
+      agent_controllers(agent, delimiter) || 'Never'
25
+    else
26
+      [
27
+        agent.schedule.humanize.titleize,
28
+        *(agent_controllers(agent, delimiter))
29
+      ].join(delimiter).html_safe
30
+    end
31
+  end
32
+
33
+  def agent_controllers(agent, delimiter = ', ')
34
+    unless agent.controllers.empty?
35
+      agent.controllers.map { |agent|
36
+        link_to(agent.name, agent_path(agent))
37
+      }.join(delimiter).html_safe
38
+    end
27 39
   end
28 40
 end

+ 6 - 10
app/views/agents/_form.html.erb

@@ -44,16 +44,12 @@
44 44
             </div>
45 45
           </div>
46 46
 
47
-          <div class="schedule-region" data-can-be-scheduled="<%= @agent.can_be_scheduled? %>">
48
-            <div class="can-be-scheduled">
49
-              <div class="form-group">
50
-                <%= f.label :controllers %>
51
-                <span class="glyphicon glyphicon-question-sign hover-help" data-content="Other than the system-defined schedule above, this agent may be run or controlled by user-defined Agents."></span>
52
-                <% eventControllers = current_user.agents.select(&:can_control_other_agents?) %>
53
-                <%= f.select(:controller_ids,
54
-                             options_for_select(eventControllers.map {|s| [s.name, s.id] },
55
-                                                @agent.controller_ids),
56
-                             {}, { multiple: true, size: 5, class: 'select2 form-control' }) %>
47
+          <div class="controller-region" data-has-controllers="<%= !@agent.controllers.empty? %>">
48
+            <div class="form-group">
49
+              <%= f.label :controllers %>
50
+              <span class="glyphicon glyphicon-question-sign hover-help" data-content="Other than the system-defined schedule above, this agent may be run or controlled by these user-defined Agents."></span>
51
+              <div class="controller-list">
52
+                <%= agent_controllers(@agent) || 'None' %>
57 53
               </div>
58 54
             </div>
59 55
           </div>